import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';
import { TransferService } from '../../transfer/service/transfer.service';
import { Subscription } from 'rxjs';
import { MessageService } from './../../../core/service/message.service';

interface Title { translate?: string; name: string; }

@Component({
  selector: 'app-recharge-header',
  templateUrl: './recharge-header.component.html',
  styleUrls: ['./recharge-header.component.scss']
})
export class RechargeHeaderComponent implements OnInit, OnDestroy {

  private title: string;

  // @Input()
  url: string;

  subscription: Subscription;

  toPage() {
    if (this.url) {
      this.router.navigateByUrl(this.url);
    } else {
      this.message.error('System error');
    }
  }

  constructor(
    private router: Router,
    private message: NzMessageService,
    private transferService: TransferService,
    private _obs: MessageService
  ) {
    this.url = '/member/center';
  }

  ngOnInit() {
     this.subscription = this.transferService.goBackUrl$.subscribe(url => {
      this.url = url;
    });
    this._obs.getMessage().subscribe(event => {
      if (event.text) {
        this.title = event.text;
      }
    });

  }

  ngOnDestroy() {
    if (this.subscription) {
      this.subscription.unsubscribe();
    }
  }

}
